home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / GXEdit Library & Doc / GXEditScrap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  14.7 KB  |  723 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:                GXEditScrap.c
  3.     
  4.     Contains:
  5.     
  6.     Written by:        Barton R. House
  7.     
  8.     Copyright:        © 1993 by Apple Computer, Inc., All rights reserved.
  9.     
  10. */
  11.  
  12. #include <Scrap.h>
  13. #include <Script.h>
  14. #include <Errors.h>
  15. #include <Fonts.h>
  16.  
  17. #include "PrintingManager.h"
  18. #include "graphics routines.h"
  19. #include "graphics libraries.h"
  20. #include "font routines.h"
  21. #include "math routines.h"
  22. #include "layout routines.h"
  23. #include "font menu library.h"
  24.  
  25. #include "GXEdit.h"
  26. #include "GXEditDebug.h"
  27. #include "GXEditDoc.h"
  28. #include "GXEditScrap.h"
  29. #include "GXEditError.h"
  30. #include "GXEditNewRun.h"
  31. #include "GXEditStyle.h"
  32.  
  33. #define    kGXEditScrapType        'gxdt'
  34. #define    kGXEditScrapMagic        0x3abf435d
  35. #define    kGXEditScrapVersion        0x0
  36.  
  37. #define    kTextScrapType        'TEXT'
  38. #define    kStyleScrapType        'styl'
  39.  
  40. #define    kBufferSize            2048
  41. #define    kChunkSize            1024
  42.  
  43. typedef struct {
  44.     gxSpoolBlock        sb;            /* this must be first */
  45.     Handle        buf;
  46.     long            * pos;
  47.     long            numBytes;
  48.     long            start;
  49.     DocPtr        dp;
  50. } MySpoolBlock;
  51.  
  52. static long MySpoolProcedure(gxSpoolCommand command, gxSpoolBlock * sb);
  53.  
  54. static Handle    ScrapToHandle(DocPtr dp);
  55. static void     HandleToScrap(DocPtr dp, Handle scrap);
  56.  
  57. static void    ScrapToText(DocPtr dp, Handle * text, long * textSize, Handle * gxStyle, long * styleSize);
  58. static void    TextToScrap(DocPtr dp, Handle text, Handle gxStyle);
  59.  
  60. static void     WriteLong(Handle scrap, long *pos, long value);
  61. static void     WriteNewRun(Handle scrap, long *pos, NewRunPtr rp);
  62. static void     WriteStyle(DocPtr dp, Handle scrap, long *pos, short styleIndex);
  63. static void    WriteData(Handle scrap, long * pos, void * buf, long size);
  64.  
  65. static void     ReadLong(Handle scrap, long *pos, long *value);
  66. static void     ReadNewRun(Handle scrap, long *pos, NewRunPtr rp);
  67. static void     ReadStyle(DocPtr dp, Handle scrap, long *pos, short *styleIndex);
  68. static void    ReadData(Handle scrap, long * pos, void * buf, long size);
  69.  
  70. static void    SetStyle(DocPtr dp, short styleIndex, ScrpSTElement * sp, long start);
  71. static short    GetStyle(DocPtr dp, ScrpSTElement * sp);
  72.  
  73. void gxEditScrapToDesk(DocPtr dp)
  74. {
  75.     Handle    scrap, text, gxStyle;
  76.     long        textSize, styleSize;
  77.     
  78.     ZeroScrap();
  79.     
  80.     /* GX Scrap Information */
  81.     
  82.     scrap = ScrapToHandle(dp);
  83.     
  84.     HLock((Handle) scrap);
  85.     
  86.     PutScrap(GetHandleSize(scrap), kGXEditScrapType, *scrap);
  87.     
  88.     HUnlock((Handle) scrap);
  89.     
  90.     DisposeHandle(scrap);
  91.     
  92.     /* Text Information -- Text Edit text and style */
  93.     
  94.     ScrapToText(dp, &text, &textSize, &gxStyle, &styleSize);
  95.     
  96.     HLock((Handle) text);
  97.     HLock((Handle) gxStyle);
  98.     
  99.     PutScrap(textSize, kTextScrapType, *text);
  100.     PutScrap(styleSize, kStyleScrapType, *gxStyle);
  101.     
  102.     HUnlock((Handle) text);
  103.     HUnlock((Handle) gxStyle);
  104.     
  105.     DisposeHandle((Handle) text);
  106.     DisposeHandle((Handle) gxStyle);
  107.     
  108. }
  109.  
  110. void gxEditScrapFromDesk(DocPtr dp)
  111. {
  112.     Handle    scrap, text, gxStyle;
  113.     long        offset;
  114.     long        length;
  115.     
  116.     if(GetScrap(nil, kGXEditScrapType, &offset) > 0) {
  117.     
  118.         scrap = NewHandle(0);
  119.         
  120.         if(GXEditDebug)
  121.             RemoveBlock((long) scrap);
  122.             
  123.         length = GetScrap(scrap, kGXEditScrapType, &offset);
  124.         
  125.         if(GXEditDebug)
  126.             AddBlock((long) scrap, length, true);
  127.                     
  128.         HandleToScrap(dp, scrap);
  129.         
  130.         DisposeHandle(scrap);
  131.         
  132.     } else if(GetScrap(nil, kTextScrapType, &offset) > 0) {
  133.     
  134.         text = NewHandle(0);
  135.         
  136.         if(GXEditDebug)
  137.             RemoveBlock((long) text);
  138.             
  139.         length = GetScrap(text, kTextScrapType, &offset);
  140.         
  141.         if(GXEditDebug)
  142.             AddBlock((long) text, length, true);
  143.             
  144.         if(GetScrap(nil, kStyleScrapType, &offset) > 0) {
  145.         
  146.             gxStyle = NewHandle(0);
  147.             
  148.             if(GXEditDebug)
  149.                 RemoveBlock((long) text);
  150.                 
  151.             length = GetScrap(gxStyle, kStyleScrapType, &offset);
  152.             
  153.             if(GXEditDebug)
  154.                 AddBlock((long) gxStyle, length, true);
  155.             
  156.         } else
  157.             gxStyle = nil;
  158.                     
  159.         TextToScrap(dp, text, gxStyle);
  160.         
  161.         DisposeHandle(text);
  162.         if(gxStyle != nil)
  163.             DisposeHandle(gxStyle);
  164.     
  165.     } else {
  166.     
  167.         gxEditEmptyScrap(dp);
  168.             
  169.     }
  170.     
  171.     
  172. }
  173.  
  174. static Handle ScrapToHandle(DocPtr dp)
  175. {
  176.     long        pos;
  177.     long        numRuns;
  178.     NewRunPtr    rp;
  179.     short        i;
  180.     Handle        scrap;
  181.     
  182.     pos = 0;
  183.     scrap = NewHandle(0);
  184.     
  185.     numRuns = dp->scrap.numRuns;
  186.     
  187.     WriteLong(scrap, &pos, kGXEditScrapMagic);
  188.     WriteLong(scrap, &pos, kGXEditScrapVersion);
  189.     WriteLong(scrap, &pos, numRuns);
  190.     
  191.     HLock((Handle) dp->scrap.runs);
  192.  
  193.     rp = * dp->scrap.runs;
  194.     for(i=0; i<numRuns; i++, rp++) {
  195.     
  196.         WriteNewRun(scrap, &pos, rp);
  197.         WriteStyle(dp, scrap, &pos, rp->styleIndex);
  198.         
  199.     }
  200.     
  201.     HUnlock((Handle) dp->scrap.runs);
  202.     
  203.     return(scrap);
  204.     
  205. }
  206.  
  207. static void WriteLong(Handle scrap, long * pos, long value)
  208. {
  209.     if(*pos + sizeof(long) > GetHandleSize(scrap) )
  210.         SetHandleSize((Handle) scrap, *pos + sizeof(long));
  211.     
  212.     *((long *) (((Ptr) *scrap) + *pos)) = value;
  213.     
  214.     *pos += sizeof(long);
  215. }
  216.  
  217. static void WriteData(Handle scrap, long * pos, void * buf, long size)
  218. {
  219.     if(*pos + size > GetHandleSize(scrap) )
  220.         SetHandleSize((Handle) scrap, *pos + size + kChunkSize);
  221.     
  222.     BlockMove((Ptr) buf, ((Ptr) *scrap) + *pos, size);
  223.     
  224.     *pos += size;
  225. }
  226.  
  227. static void WriteNewRun(Handle scrap, long * pos, NewRunPtr rp)
  228. {
  229.     long        size;
  230.     
  231.     if(*pos + sizeof(NewRunRec) > GetHandleSize(scrap) )
  232.         SetHandleSize((Handle) scrap, *pos + sizeof(NewRunRec));
  233.     
  234.     *((NewRunPtr) (((Ptr) *scrap) + *pos)) = *rp;
  235.     
  236.     *pos += sizeof(NewRunRec);
  237.  
  238.     /* write out the text information */
  239.  
  240.     HLock((Handle) rp->text);
  241.     
  242.     size = rp->numText;
  243.     WriteData(scrap, pos, (void *) *rp->text, size);
  244.     
  245.     HUnlock((Handle) rp->text);
  246.     
  247. }
  248.  
  249. void gxEditDisposeScrap(DocPtr dp)
  250. {    
  251.     gxEditEmptyScrap(dp);
  252.     
  253.     DisposeHandle((Handle) dp->scrap.runs);
  254.     dp->scrap.runs = nil;
  255.         
  256. }
  257.  
  258. void gxEditEmptyScrap(DocPtr dp)
  259. {
  260.     NewRunPtr        rp;
  261.     short            i;
  262.     
  263.     /* walk the runs that are in the scrap now, decrementing the style ref counts */
  264.     
  265.     HLock((Handle) dp->scrap.runs);
  266.     
  267.     rp = * dp->scrap.runs;
  268.     for(i=0; i<dp->scrap.numRuns; i++, rp++)
  269.         DisposeNewRun(dp, rp);
  270.         
  271.     HUnlock((Handle) dp->scrap.runs);
  272.  
  273.     SetHandleSize((Handle) dp->scrap.runs, 0);
  274.  
  275.     dp->scrap.numRuns = 0;
  276.     
  277. }
  278.  
  279. static void HandleToScrap(DocPtr dp, Handle scrap)
  280. {
  281.     long        pos;
  282.     long        magic;
  283.     long        version;
  284.     long        numRuns;
  285.     NewRunPtr    rp;
  286.     short        i;
  287.     
  288.     pos = 0;
  289.     
  290.     ReadLong(scrap, &pos, &magic);
  291.     ReadLong(scrap, &pos, &version);
  292.     ReadLong(scrap, &pos, &numRuns);
  293.     
  294.     if(magic != kGXEditScrapMagic || version != kGXEditScrapVersion)
  295.         gxEditPostError(dp, gx_edit_internal_fatal_error);
  296.     
  297.     if(numRuns < 0)
  298.         gxEditPostError(dp, gx_edit_internal_fatal_error);
  299.     
  300.     /* clean up old scrap */
  301.     
  302.     gxEditEmptyScrap(dp);
  303.         
  304.     /* setup the scrap runs in the document */
  305.         
  306.     dp->scrap.numRuns = numRuns;
  307.     SetHandleSize((Handle) dp->scrap.runs, sizeof(NewRunRec) * numRuns);
  308.     dp->scrap.numText = 0;
  309.     
  310.     HLock((Handle) dp->scrap.runs);
  311.  
  312.     rp = * dp->scrap.runs;
  313.     for(i=0; i<numRuns; i++, rp++) {
  314.     
  315.         ReadNewRun(scrap, &pos, rp);
  316.         ReadStyle(dp, scrap, &pos, &rp->styleIndex);
  317.         
  318.         IncrementDocStyleRefCount(dp, rp->styleIndex);
  319.         
  320.         dp->scrap.numText += rp->numText;
  321.     }
  322.     
  323.     HUnlock((Handle) dp->scrap.runs);
  324.     
  325. }
  326.  
  327. static void ReadLong(Handle scrap, long * pos, long * value)
  328. {
  329.     if(*pos + sizeof(long) > GetHandleSize(scrap) )
  330.         gxEditPostError(nil, gx_edit_internal_fatal_error);
  331.         
  332.     *value = *((long *) (((Ptr) *scrap) + *pos));
  333.     
  334.     *pos += sizeof(long);
  335. }
  336.  
  337. static void ReadData(Handle scrap, long * pos, void * buf, long size)
  338. {
  339.     if(*pos + size > GetHandleSize(scrap) )
  340.         gxEditPostError(nil, gx_edit_internal_fatal_error);
  341.     
  342.     BlockMove(((Ptr) *scrap) + *pos, (Ptr) buf, size);
  343.         
  344.     *pos += size;
  345. }
  346.  
  347.  
  348. static void ReadNewRun(Handle scrap, long * pos, NewRunPtr rp)
  349. {
  350.     long    size;
  351.     
  352.     if(*pos + sizeof(NewRunRec) > GetHandleSize(scrap) )
  353.         gxEditPostError(nil, gx_edit_internal_fatal_error);
  354.         
  355.     *rp = *((NewRunPtr) (((Ptr) *scrap) + *pos));
  356.     
  357.     *pos += sizeof(NewRunRec);
  358.     
  359.     /* read in the text */
  360.  
  361.     size = rp->numText;
  362.     rp->text = (void **) NewHandle(size);
  363.     
  364.     ReadData(scrap, pos, *rp->text, size);
  365.     
  366. }
  367.  
  368. static void ReadStyle(DocPtr dp, Handle scrap, long * pos, short * styleIndex)
  369. {
  370.     MySpoolBlock        msb;
  371.     gxShape            emptyShape;
  372.     StyleRec            gxStyle;
  373.     long                styleSize;
  374.     
  375.     /* read size of following data */
  376.     
  377.     ReadLong(scrap, pos, &styleSize);
  378.     
  379.     /* read in the GX gxStyle information */
  380.     
  381.     msb.sb.buffer = NewPtr(kBufferSize);
  382.     msb.sb.bufferSize = kBufferSize;
  383.     msb.sb.spoolProcedure = MySpoolProcedure;
  384.     
  385.     msb.numBytes = styleSize;
  386.     msb.buf = scrap;
  387.     msb.pos = pos;
  388.     msb.start = *pos;
  389.     msb.dp = dp;
  390.     
  391.     emptyShape = GXUnflattenShape((gxSpoolBlock *) &msb, 1, &dp->docViewPort );
  392.     
  393.     /* check that the correct number of bytes was read */
  394.     
  395.     if(msb.numBytes != 0)
  396.         gxEditPostError(dp, gx_edit_internal_fatal_error);
  397.     
  398.     DisposePtr(msb.sb.buffer);
  399.     
  400.     /* now lets convert the gxStyle to a gxStyle index */
  401.     
  402.     gxStyle.textStyle = GXGetShapeStyle(emptyShape);
  403.     gxStyle.textSize = FixedToInt(GXGetStyleTextSize(gxStyle.textStyle));
  404.     gxStyle.textFont = GXGetStyleFont(gxStyle.textStyle);
  405.     
  406.     *styleIndex = FindDocStyle(dp, &gxStyle);
  407.     
  408.     if(*styleIndex == -1)
  409.         *styleIndex = AddDocTextStyle(dp, gxStyle.textStyle);
  410.  
  411.     GXDisposeShape(emptyShape);
  412.     
  413. }
  414.  
  415. static void WriteStyle(DocPtr dp, Handle scrap, long * pos, short styleIndex)
  416. {
  417.     MySpoolBlock        msb;
  418.     gxShape            emptyShape;
  419.     long                startOfStyle;
  420.     long                endOfStyle;
  421.     StylePtr            sp;
  422.     long                styleSize = 0;        /* need a dummy value, 'cause it gets rewritten later */
  423.     
  424.     startOfStyle = *pos;        /* save the position so that we can write out the actual size of the gxStyle */
  425.     
  426.     WriteLong(scrap, pos, styleSize);
  427.     
  428.     /* save out the flatten gxStyle information */
  429.     
  430.     msb.sb.buffer = NewPtr(kBufferSize);
  431.     msb.sb.bufferSize = kBufferSize;
  432.     msb.sb.spoolProcedure = MySpoolProcedure;
  433.     
  434.     msb.numBytes = 0;
  435.     msb.buf = scrap;
  436.     msb.pos = pos;
  437.     msb.start = *pos;
  438.     msb.dp = dp;
  439.     
  440.     /* create an empty gxShape and set the gxStyle to the gxStyle we want to save */
  441.     
  442.     sp = GetDocStyle(dp, styleIndex);
  443.     
  444.     emptyShape = GXNewShape(gxEmptyType);
  445.     GXSetShapeStyle(emptyShape, sp->textStyle);
  446.     
  447.     /* look into setting the flags so that a list of fonts that are used is generated */
  448.     
  449.     GXFlattenShape(emptyShape, (gxFlattenFlag) 0, (gxSpoolBlock *) &msb);
  450.     
  451.     /* dispose of the temporary gxShape */
  452.     
  453.     GXDisposeShape(emptyShape);
  454.  
  455.     /* free up the buffer */
  456.     
  457.     DisposePtr(msb.sb.buffer);
  458.  
  459.     /* now record the actual gxStyle size */
  460.     
  461.     endOfStyle = *pos;
  462.  
  463.     styleSize = endOfStyle - startOfStyle - sizeof(long);
  464.  
  465.     
  466.     if(msb.numBytes  != styleSize)            /* double check the number of bytes written */
  467.         gxEditPostError(dp, gx_edit_internal_fatal_error);
  468.         
  469.     *pos = startOfStyle;
  470.     WriteLong(scrap, pos, styleSize);
  471.     *pos = endOfStyle;
  472.     
  473.     
  474. }
  475.  
  476. static long MySpoolProcedure(gxSpoolCommand command, gxSpoolBlock * sb)
  477. {
  478.     long                count;
  479.     MySpoolBlock        * msb;
  480.     
  481.     msb = (MySpoolBlock *) sb;
  482.     
  483.     switch(command) {
  484.     
  485.     case gxOpenReadSpool:
  486.     case gxOpenWriteSpool:
  487.     
  488.         *msb->pos = msb->start;
  489.  
  490.         break;
  491.         
  492.     case gxReadSpool:
  493.     
  494.         count = sb->count;
  495.         
  496.         if(count > msb->numBytes) {
  497.         
  498.             count = msb->numBytes;
  499.             sb->bufferSize = msb->numBytes;
  500.             
  501.         }
  502.         
  503.         ReadData(msb->buf, msb->pos, sb->buffer, count);
  504.         
  505.         msb->numBytes -= count;
  506.         
  507.         break;
  508.         
  509.     case gxWriteSpool:
  510.  
  511.         count = sb->count;
  512.         
  513.         WriteData(msb->buf, msb->pos, sb->buffer, count);
  514.                 
  515.         msb->numBytes += count;
  516.         
  517.         break;
  518.         
  519.     case gxCloseSpool:
  520.         break;
  521.     }
  522.     
  523.     return(noErr);
  524.     
  525. }
  526.  
  527.  
  528. static void ScrapToText(DocPtr dp, Handle * textPtr, long * textSizePtr, Handle * stylePtr, long * styleSizePtr)
  529. {
  530.     long                pos;
  531.     long                numRuns;
  532.     NewRunPtr        rp;
  533.     short            i;
  534.     Handle            text, gxStyle;
  535.     ScrpSTElement        * sp;
  536.     StScrpRec            * spHdr;
  537.     long                styleSize;
  538.  
  539.     pos = 0;
  540.     text = NewHandle(0);
  541.     
  542.     numRuns = dp->scrap.numRuns;
  543.     
  544.     styleSize = sizeof(short) + (sizeof(ScrpSTElement) * numRuns);
  545.     gxStyle = NewHandle(styleSize);
  546.     
  547.     HLock((Handle) gxStyle);
  548.     HLock((Handle) dp->scrap.runs);
  549.  
  550.     spHdr = (StScrpRec *) *gxStyle;
  551.     
  552.     spHdr->scrpNStyles = numRuns;
  553.     sp = (ScrpSTElement *) &spHdr->scrpStyleTab;
  554.     
  555.     rp = * dp->scrap.runs;
  556.     for(i=0; i<numRuns; i++, rp++) {
  557.         SetStyle(dp, rp->styleIndex, sp++, pos);
  558.         WriteData(text, &pos, *rp->text,  rp->numText);
  559.     }
  560.     
  561.     HUnlock((Handle) dp->scrap.runs);
  562.     HUnlock((Handle) gxStyle);
  563.     
  564.     *textPtr = text;
  565.     *textSizePtr = pos;
  566.     *stylePtr = gxStyle;
  567.     *styleSizePtr = styleSize;
  568. }
  569.  
  570. static void TextToScrap(DocPtr dp, Handle text, Handle gxStyle)
  571. {
  572.     NewRunPtr        rp;
  573.     short            numText;
  574.     short            numStyles;
  575.     StScrpRec            * styleHdr;
  576.     ScrpSTElement        * sp;
  577.     short            styleIndex;
  578.     short            pos;
  579.     short            runLength;
  580.     
  581.     HLock((Handle) text);
  582.     
  583.     if(gxStyle != nil) {
  584.     
  585.         HLock((Handle) gxStyle);
  586.         
  587.         styleHdr = (StScrpRec *) *gxStyle;
  588.     
  589.         numStyles = styleHdr->scrpNStyles;
  590.         
  591.         sp = (ScrpSTElement *) &styleHdr->scrpStyleTab;
  592.         
  593.     } else {
  594.     
  595.         numStyles = 0;
  596.         sp = nil;
  597.         
  598.     }
  599.     
  600.     gxEditEmptyScrap(dp);
  601.         
  602.     styleIndex = dp->emptyStyle;        /* default gxStyle is the current empty gxStyle */
  603.     numText = GetHandleSize(text);
  604.     
  605.     if(numStyles > 0)
  606.         dp->scrap.numRuns = numStyles;
  607.     else
  608.         dp->scrap.numRuns = 1;
  609.  
  610.  
  611.     SetHandleSize((Handle) dp->scrap.runs, sizeof(NewRunRec) * dp->scrap.numRuns);
  612.     dp->scrap.numText = numText;
  613.     
  614.     HLock((Handle) dp->scrap.runs);
  615.     
  616.     rp = *dp->scrap.runs;
  617.     pos = 0;
  618.     
  619.     while(pos < numText) {
  620.     
  621.         if(numStyles)
  622.             runLength = sp->scrpStartChar - pos;
  623.         else
  624.             runLength = numText - pos;
  625.         
  626.         if(runLength) {
  627.     
  628.             NewNewRun(dp, rp, styleIndex);
  629.         
  630.             InsertNewRunText(dp,  rp,  0, *text + pos,  runLength);
  631.             
  632.             pos += runLength;
  633.         }
  634.         
  635.         if(numStyles) {
  636.         
  637.             styleIndex = GetStyle(dp, sp);
  638.             
  639.             numStyles--;
  640.             sp++;
  641.         }
  642.  
  643.     }
  644.         
  645.     HUnlock((Handle) text);
  646.     HUnlock((Handle) dp->scrap.runs);
  647.     
  648.     if(gxStyle != nil)
  649.         HUnlock((Handle) gxStyle);
  650.     
  651. }
  652.  
  653. static short GetStyle(DocPtr dp, ScrpSTElement * sp)
  654. {
  655.     short        scrapSize, styleIndex;
  656.     gxFont            textFont;
  657.     Str255        gxFontName;
  658.     
  659.     scrapSize = sp->scrpSize;
  660.     if (scrapSize <= 0)
  661.         scrapSize = GetDefFontSize();
  662.         
  663.     styleIndex = SetDocStyleTextSize(dp, 0, scrapSize);
  664.  
  665.     GetFontName(sp->scrpFont, gxFontName);
  666.     
  667.     textFont = (gxFont) -1;
  668.     
  669.     GXFindFonts(nil, gxFamilyFontName, gxMacintoshPlatform, gxRomanScript, gxNoLanguage,
  670.                                     gxFontName[0], &gxFontName[1], 1, 1, &textFont);
  671.     
  672.     if(textFont != (gxFont) -1)
  673.         styleIndex = SetDocStyleTextFont(dp, styleIndex, textFont);
  674.     
  675.     return(styleIndex);
  676. }
  677.  
  678. static void SetStyle(DocPtr dp, short styleIndex, ScrpSTElement * sp, long start)
  679. {
  680.     gxFont            textFont;
  681.     short            textSize;
  682.     short            fontNum;
  683.     short            oldTextSize;
  684.     short            oldFontNum;
  685.     FontInfo            info;
  686.     long                textFace;
  687.     
  688.     textFont = GetDocStyleTextFont(dp, styleIndex);
  689.     textSize = GetDocStyleTextSize(dp, styleIndex);
  690.     
  691.     if (textSize <= 0 || textSize >= 127)
  692.         textSize = GetDefFontSize();
  693.  
  694.     fontNum = FontToQD(textFont, &textFace);
  695.     
  696. /*    gxFontName[0] = GXFindFontName(textFont,  gxFamilyFontName, gxMacintoshPlatform, gxRomanScript, gxNoLanguage,*/
  697. /*                                    &gxFontName[1], nil);*/
  698. /*    */
  699. /*    GetFNum(gxFontName, &fontNum);*/
  700.     
  701.     /* This assumes a grafPort is alive somewhere !!! */
  702.     
  703.     oldFontNum = qd.thePort->txFont;
  704.     oldTextSize = qd.thePort->txSize;
  705.     TextFont(fontNum);
  706.     TextSize(textSize);
  707.     GetFontInfo(&info);
  708.     TextSize(oldTextSize);
  709.     TextFont(oldFontNum);
  710.     
  711.     sp->scrpStartChar = start;
  712.     sp->scrpHeight = info.ascent + info.descent;
  713.     sp->scrpAscent = info.ascent;
  714.     sp->scrpFont = fontNum;
  715.     sp->scrpFace = textFace;
  716.     sp->scrpSize = textSize;
  717.     sp->scrpColor.red = 0;
  718.     sp->scrpColor.green = 0;
  719.     sp->scrpColor.blue = 0;
  720.     
  721. }
  722.  
  723.